import fetch from 'common/src/utils/fetch'
import UTILS from "common/src/utils/utils";

/**
 * 培养方案列表
 */
export function findCultureSchemeList(data) {
  let newData = Object.assign({}, data);
  if(newData.trainingCategory && newData.trainingCategory instanceof Array) {
    newData.trainingCategory = newData.trainingCategory.join(",");
  }
  return fetch({
    url: '/api/cultureservice/cultureScheme/findCultureSchemeList',
    method: 'post',
    data: newData
  })
}

export function findCultureSchemeListForMange(data) {
  let newData = Object.assign({}, data);
  if(newData.trainingCategory && newData.trainingCategory instanceof Array) {
    newData.trainingCategory = newData.trainingCategory.join(",");
  }
  return fetch({
    url: '/api/cultureservice/cultureScheme/cultureSchemeListForMange',
    method: 'post',
    data: newData
  })
}

/**
 * 新增培养方案
 */
export function addCultureScheme(data) {
  let newData = Object.assign({}, data);
  if(newData.trainingCategory && newData.trainingCategory instanceof Array) {
    newData.trainingCategory = newData.trainingCategory.join(",");
  }
  return fetch({
    url: '/api/cultureservice/cultureScheme/addCultureScheme',
    method: 'post',
    data: newData
  })
}

/**
 * 复制培养方案
 */
export function copyCultureScheme(data) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/copyCultureScheme',
    method: 'post',
    data
  })
}
/**
 * 复制培养方案
 */
export function copyCultureSchemeList(data) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/copyCultureScheme',
    method: 'post',
    data
  })
}
/**
 * 修改培养方案
 */
export function updateCultureScheme(data) {
  let newData = Object.assign({}, data);
  if(newData.trainingCategory && newData.trainingCategory instanceof Array) {
    newData.trainingCategory = newData.trainingCategory.join(",");
  }
  return fetch({
    url: '/api/cultureservice/cultureScheme/updateCultureScheme',
    method: 'put',
    data: newData
  })
}

/**
 * 删除培养方案
 */
export function batchDelCultureScheme(data) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/batchDelCultureScheme',
    method: 'delete',
    data
  })
}

/**
 * 查询单个培养方案
 * @param data
 */
export function findCultureSchemeById(params) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/findCultureSchemeById',
    method: 'get',
    params: params
  })
}

/**
 * 获取章节内容（模板或方案）
 * @param data
 */


export function getSchemeChapters(params) {
  return fetch({

    url:
      '/api/cultureservice/cultureSchemeDetail/findCultScheDetailOrTemplateList',
    method: 'get',
    params: params
  })
}

/**
 * 更新章节内容（模板或方案）
 * @param data
 */
export function updateSchemeChapters(data) {
  return fetch({
    url:
      '/api/cultureservice/cultureSchemeDetail/upateCultScheDetailOrTemplate',
    method: 'post',
    data
  })
}

/**
 * 查询模板列表
 * @param data
 */
export function cultureTemplateList(params) {
  return fetch({
    url: '/api/cultureservice/cultureTemplate/cultureTemplateList',
    method: 'get',
    params: params
  })
}

/**
 * 新增表格内容
 * @param data
 */
export function getTableId(params) {
  return fetch({
    url: '/api/cultureservice/cultureSchemeDetail/addDetailTableByContentId',
    method: 'get',
    params: params
  })
}

/**
 * 查询单个培养方案
 * @param data
 */
export function getCultureScheme(params) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/findCultureScheme',
    method: 'get',
    params: params
  })
}
export function findCultureSchemeInId(params) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/findCultureSchemeInId',
    method: 'get',
    params: params
  })
}
/**
 * 我的方案
 */
export function getMyCultureScheme() {
  return fetch({
    url: '/api/cultureservice/studentCultureRel/queryMyCultureScheme',
    method: 'get'
  })
}

/**
 * 我的课程
 */
export function getMyCourses() {
  return fetch({
    url: '/api/cultureservice/studentCultureRel/queryMyCourses',
    method: 'get'
  })
}

/**
 * 查询单个培养方案
 * @param data
 */
export function getCultureSchemeById(params) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/findCultureSchemeById',
    method: 'get',
    params: params
  })
}

/**
 * 提交培养方案审批
 * @param data
 */
export function checkCultureScheme(data) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/checkCultureScheme',
    method: 'post',
    data
  })
}

/**
 * 导出培养方案
 * @param {Object} params
 */
export function schemeExport(params) {
  const url = '/api/cultureservice/cultureScheme/exportCultureScheme'
  const remove_params = ['pageNum_', 'pageSize_']
  let queryParam = ''
  for (const key in params) {
    // 去掉分页
    if (remove_params.includes(key)) {
      continue
    }
    // 去掉空参数
    if (params[key] == '') {
      continue
    }
    queryParam += `${key}=${params[key]}&`
  }
  window.open(`${url}?${queryParam}`)
}

/**
 * 导出培养方案
 * @param {Object} params
 */
export function schemeExportPdf(params) {
  const url = '/api/cultureservice/cultureScheme/exportCultureSchemePdf'
  const remove_params = ['pageNum_', 'pageSize_']
  let queryParam = ''
  for (const key in params) {
    // 去掉分页
    if (remove_params.includes(key)) {
      continue
    }
    // 去掉空参数
    if (params[key] == '') {
      continue
    }
    queryParam += `${key}=${params[key]}&`
  }
  window.open(`${url}?${queryParam}`)
}

/**
 * 导出培养方案
 * @param {Object} params
 */
export function schemeListExport(params) {
  const url = '/api/cultureservice/cultureScheme/exportCultureSchemeZip'
  const remove_params = ['pageNum_', 'pageSize_']
  let queryParam = ''
  for (const key in params) {
    // 去掉分页
    if (remove_params.includes(key)) {
      continue
    }
    // 去掉空参数
    if (params[key] == '') {
      continue
    }
    queryParam += `${key}=${params[key]}&`
  }
  window.open(`${url}?${queryParam}`)
}

// 根据Id查看模板详情
export function getTemplateById(id) {
  return fetch({
    url: '/api/cultureservice/cultureTemplate/convert/' + id,
    method: 'GET'
  })
}

/**
 * 批量新增培养方案
 * @param data
 */
export function batchAddCultureScheme(data) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/batchAddCultureScheme',
    method: 'post',
    data
  })
}

/**
 * 新增课程分组信息
 * @param data
 */
export function addCourseLabelRelGroup(data) {
  return fetch({
    url: '/api/cultureservice/courseLabelRelGroup/addCourseLabelRelGroup',
    method: 'post',
    data
  })
}

/**
 * 当前模板（方案）是研究生还是本科生
 * @param data
 */
export function getIsGraduate(id, type) {
  return fetch({
    url:
      '/api/cultureservice/courseLabelRelation/getIsGraduate/' +
      id +
      '?type=' +
      type,
    method: 'GET'
  })
}

/**
 * 培养方案模板根据条件查询不分页——new
 * @param data
 */
export function cultureTemplateListNew(data) {
  let newData = Object.assign({}, data);
  if(newData.trainingCategory && newData.trainingCategory instanceof Array) {
    newData.trainingCategory = newData.trainingCategory.join(",");
  }
  return fetch({
    url: '/api/cultureservice/cultureTemplate/cultureTemplateListNew',
    method: 'post',
    data: newData
  })
}

/**
 * 查询大小类校内专业
 * @param data
 */
export function findProfessionByParam(data) {
  return fetch({
    url: '/api/commonservice/campusProfession/findProfessionByParam',
    method: 'post',
    data
  })
}

/**
 * 查询专业对应的大类培养方案列表
 * @param data
 */
export function findTrainingCategoryScheme(data) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/findTrainingCategoryScheme',
    method: 'post',
    data
  })
}

/**
 * 查询某年某学院某专业的培养方案列表
 * @param data
 */
export function findCultureSchemeListByYear(data) {
  let newData = Object.assign({}, data);
  if(newData.trainingCategory && newData.trainingCategory instanceof Array) {
    newData.trainingCategory = newData.trainingCategory.join(",");
  }
  return fetch({
    url: '/api/cultureservice/cultureScheme/findCultureSchemeListByYear',
    method: 'post',
    data: newData
  })
}

/**
 * 获取培养方案的章节名称列表或章节内容
 * @param data
 */
export function findCultureScheDetailList(data) {
  return fetch({
    url: '/api/cultureservice/cultureSchemeDetail/findCultureScheDetailList',
    method: 'post',
    data
  })
}

/*
 * 当前培养方案分方向的数据
 * @param data
 */
export function findDirectionDataByScheme(id) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/findDirectionDataByScheme?id=' + id,
    method: 'GET'
  })
}
/*
 * 当前培养方案分方向的数据
 * @param data
 */
export function findCampusProfessionById(id) {
  return fetch({
    url:
      '/api/commonservice/campusProfession/findCampusProfessionById?id=' + id,
    method: 'GET'
  })
}

/**
 * 新增课程方向
 * @param data
 */
export function addDirectionLableRelToCourse(data) {
  return fetch({
    url: '/api/cultureservice/directionLableRel/addDirectionLableRelToCourse',
    method: 'post',
    data
  })
}
/**
 * 删除课程方向
 * @param data
 */
export function delDirectionLableRelToCourse(data) {
  return fetch({
    url: '/api/cultureservice/directionLableRel/delDirectionLableRelToCourse',
    method: 'post',
    data
  })
}

/**
 *删除培养规则
 * @param {data} data
 */
export function deleteCourseLabelRelGroup(data) {
  return fetch({
    url: '/api/cultureservice/courseLabelRelGroup/deleteCourseLabelRelGroup',
    method: 'delete',
    headers: {
      'Content-Type': 'application/json'
    },
    data
  })
}

/**
 * 提交前校验章节内容（ 方案）
 * @param data
 */
export function checkCultScheDetail(data) {
  return fetch({
    url: '/api/cultureservice/cultureSchemeDetail/checkCultScheDetail',
    method: 'post',
    data
  })
}

/**
 * 培养方案导出pdf或者word压缩包
 * @param {Object} params
 */
export function exportCultureSchemePdfOrWordZip(params) {
  const url ='/api/cultureservice/cultureScheme/exportCultureSchemePdfOrWordZip';
    let queryParams = '';
      for (let item in params) {
          if (params[item] === '') {
              continue;
          }
          queryParams += `${item}=${params[item]}&`;
      }
    queryParams = queryParams.substring(0, queryParams.lastIndexOf('&'));
    window.open(`${url}?${queryParams}`);
}

/**
 * 查询批量修改列表
 * @param data
 */
export function findBatchCultureSchemeTemplateList(data) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/findBatchCultureSchemeTemplateList',
    method: 'post',
    data
  })
}

/**
 * 查询模板的课程类别 -- 只取叶子节点
 * @param data
 */
export function findCoursesLabelList(id) {
  return fetch({
    url:
      '/api/cultureservice/cultureScheme/findCoursesLabelList?templateId=' + id,
    method: 'GET'
  })
}

/**
 * 查询章节样例 -- 查询当前模板的章节样例
 * @param data
 */
export function findContentList(id) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/findContentList?templateId=' + id,
    method: 'GET'
  })
}

/**
 * 批量新增课程
 * @param data
 */
export function batchAddCourses(data) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/batchAddCourses',
    method: 'post',
    data
  })
}

/**
 * 批量替换课程
 * @param data
 */
export function batchReplaceCourses(data) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/batchReplaceCourses',
    method: 'post',
    data
  })
}
/**
 * 批量删除课程
 * @param data
 */
export function batchDelCourses(data) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/batchDelCourses',
    method: 'post',
    data
  })
}
/**
 * 批量修改章节样例
 * @param data
 */
export function batchEditContents(data) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/batchEditContents',
    method: 'post',
    data
  })
}

/**
 * 点击培养方案变更按钮
 * @param data
 */
export function changeCultureScheme(data) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/changeCultureScheme',
    method: 'get',
    params: {
      id: data.id,
      isSynchronousPlan: data.isSynchronousPlan,
    },
  })
}


/**
 * 强化班查询已发布状态查询培养方案
 * @param params
 */
export function findCultureSchemeListByStrengthClass(params) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/findCultureSchemeListByStrengthClass',
    method: 'post',
    data: params
  })
}
/**
 * 培养方案开关设置(查询)
 * @param data
 */
export function schemefindResult(data) {
  return fetch({
    url:
      '/api/cultureservice/SchemaSetTurn/findResult',
    method: 'post',
    data
  })
}
/**
 * 培养方案开关设置(提交)
 * @param data
 */
export function schemeAddSet(data) {
  return fetch({
    url:
      '/api/cultureservice/SchemaSetTurn/addSet',
    method: 'post',
    data
  })
}
/**
 * 批量修改培养方案(查询章节)
 * @param data
 */
export function findNodeList(id) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/findNodeList?cultureIdList=' + id,
    method: 'GET'
  })
}
/**
 * 批量修改培养方案(提交内容)
 * @param data
 */
export function updateCultureTemolateContent(data) {
  return fetch({
    url:
      '/api/cultureservice/cultureScheme/updateCultureTemolateContent',
    method: 'post',
    data
  })
}
/**
 * 批量修改培养方案(查询方案下的课程)
 * @param data
 */
export function findCuturecourseList(id) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/findCuturecourseList?cultureIdList=' + id,
    method: 'GET',
  })
}
/**
 * 批量修改培养方案(批量新增)
 * @param data
 */
export function bachAddCultureCourse(id, newCode, lableId, compulsory, isSynchronousPlan) {
  return fetch({
    url:
      "/api/cultureservice/cultureScheme/bachAddCultureCourse?cultureIdList=" +
      id +
      "&courseCodeNew=" +
      newCode +
      "&couselableid=" +
      lableId +
      "&compulsory=" +
      compulsory +
      "&isSynchronousPlan=" +
      isSynchronousPlan,
    method: "GET"
  });
}
/**
 * 批量修改培养方案(批量替换)
 * @param data
 */
export function bachUpdateCultureCourse(
         id,
         oldCode,
         newCode,
         isSynchronousPlan
       ) {
         return fetch({
           url:
             "/api/cultureservice/cultureScheme/bachUpdateCultureCourse?cultureIdList=" +
             id +
             "&courseCodeOld=" +
             oldCode +
             "&courseCodeNew=" +
             newCode +
             "&isSynchronousPlan=" +
             isSynchronousPlan,
           method: "GET"
         });
       }
/**
 * 批量修改培养方案(批量删除)
 * @param data
 */
export function bachdaleteCultureCourse(id, oldCode, isSynchronousPlan) {
         return fetch({
           url:
             "/api/cultureservice/cultureScheme/bachdaleteCultureCourse?cultureIdList=" +
             id +
             "&courseCodeOld=" +
             oldCode +
             "&isSynchronousPlan=" +
             isSynchronousPlan,
           method: "GET"
         });
       }
/**
 * 撤销审批中的培养方案
 * @param data
 */
export function rejectApprove(id) {
  return fetch({
    url: '/api/cultureservice/cultureScheme/rejectApprove?cultureId=' + id,
    method: 'get',
  })
}
/**
 * 页面导出excel
 * @param {*} data 
 */
export function exportPage(data){
    return fetch({
        url: `/api/cultureservice/cultureScheme/exportCultureSchemeList`,
        method: 'post',
        data: data,
        responseType: 'blob'
    }).then(res => {
        UTILS.downloadFile(res, '培养方案列表.xls', 'application/vnd.ms-excel;charset=utf-8');
    });
}
/**
 * 批量修改培养方案(提交内容)
 * @param data
 */
export function findCultureSchemeListByIds(data) {
  return fetch({
    url:
      '/api/cultureservice/cultureScheme/findCultureSchemeListByIds',
    method: 'post',
    data
  })
}
/**
 * 查询学科专业委员会
 * @param data
 */
export function findSubjectMajorRole(data) {
  return fetch({
    url:
      '/api/cultureservice/courses/findSubjectMajorRole',
    method: 'post',
    data
  })
}